package controller

import (
	"go-bff-scaffold/api"
	"go-bff-scaffold/dto"
	"go-bff-scaffold/service"

	"github.com/gin-gonic/gin"
)

func UserController(engine *gin.Engine) {
	engine.GET("/user", userInfo)
}

func userInfo(ctx *gin.Context) {
	// 接口聚合
	bffServiceDefine := api.NewGenericBffService("./data_conf/user_data_define.json")
	bffServiceDefine.CombineAPIs(func(data []*api.ResponseValue) {
		// 业务处理
		userService := service.NewUserService(&dto.UserParam{
			Name:    data[1].Resp,
			Message: data[0].Resp,
		})
		ctx.JSON(200, gin.H{
			"status": "success",
			"result": userService.GetUserInfo(),
		})
	})
}
